package com.funny.rabbitmq.pubsub.direct;

import com.funny.rabbitmq.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.util.Scanner;

public class Producer {

    private final static String EXCHANGE_NAME = "logs.direct";
    private final static String QUEUE_NAME = "console";
    private final static String ROUTING_KEY = "error";


    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();
        // 声明交换机
//        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.FANOUT, true);
        // 声明队列
//        channel.queueDeclare(QUEUE_NAME, true, false, false, null);
        // 将路由键与队列、交换机绑定
//        channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, ROUTING_KEY);

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int i = scanner.nextInt();
            String msg = "hello world_" + i;
            channel.basicPublish(EXCHANGE_NAME, ROUTING_KEY, MessageProperties.PERSISTENT_TEXT_PLAIN, msg.getBytes());
            System.out.println("消息发送成功");
        }
    }
}
